package org.algorithm.wE1.数组.三月.第四周;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhx
 * @date 2022-03-21 星期一18:26
 *
 * url: https://leetcode-cn.com/problems/pascals-triangle/
 */
public class 杨辉三角I {

    public static void main(String[] args) {
        System.out.println(generate(5));
    }


    /**
     * 输入: numRows = 5
     * 输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
     *
     * 输入: numRows = 1
     * 输出: [[1]]
     */
    public static List<List<Integer>> generate(int numRows) {
        if(numRows == 0){
            return null;
        }
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i <numRows ; i++) {
            List<Integer> row = new ArrayList<>();
            for (int j = 0; j <=i ; j++) {
                if(j==0||j==i){
                    row.add(1);
                }else {
                    row.add(list.get(i-1).get(j-1)+list.get(i-1).get(j));
                }
            }
            list.add(row);
        }
        return list;
    }
}
